package com.whw.fy.service.impl;

import com.whw.fy.entity.*;
import com.whw.fy.mapper.*;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

import com.whw.fy.service.InstructionalSupervisionService;
@Service
public class InstructionalSupervisionServiceImpl implements InstructionalSupervisionService{

    @Resource
    private InstructionalSupervisionMapper instructionalSupervisionMapper;
    @Resource
    private StaffMapper staffMapper;

    @Override
    public Message deleteByPrimaryKey(Integer instructionalSupervisionId) {
        return instructionalSupervisionMapper.deleteByPrimaryKey(instructionalSupervisionId)>0?Message.success(null):Message.fail(null);
    }

    @Override
    public Message insertSelective(InstructionalSupervision record) {
        return instructionalSupervisionMapper.insertSelective(record)>0?Message.success(null):Message.fail(null);
    }

    @Override
    public Message selectByPrimaryKey(Integer instructionalSupervisionId) {
        return Message.success(null).add(initInstructionalSupervision(instructionalSupervisionMapper.selectByPrimaryKey(instructionalSupervisionId)));
    }

    @Override
    public Message updateByPrimaryKeySelective(InstructionalSupervision record) {
        return instructionalSupervisionMapper.updateByPrimaryKeySelective(record)>0?Message.success(null):Message.fail(null);
    }

    @Override
    public Message updateIncInstructionalSupervisionStatusByInstructionalSupervisionId(Integer addedInstructionalSupervisionStatus,Integer instructionalSupervisionId) {
        return instructionalSupervisionMapper.updateIncInstructionalSupervisionStatusByInstructionalSupervisionId(addedInstructionalSupervisionStatus,instructionalSupervisionId)>0?Message.success(null):Message.fail(null);
    }

    @Override
    public Message selectAll() {
        List<InstructionalSupervision> list = instructionalSupervisionMapper.selectAll();
        for (InstructionalSupervision instructionalSupervision:list)
            initInstructionalSupervision(instructionalSupervision);
        return Message.success(null).add(list);
    }

    @Override
    public Message selectallByTeacherIdJurisdictionEight(int staffId) {
        List<InstructionalSupervision> list = instructionalSupervisionMapper.selectAllByInstructionalSupervisionTeacherId(staffId);
        for (InstructionalSupervision instructionalSupervision:list)
            initInstructionalSupervision(instructionalSupervision);
        return Message.success(null).add(list);
    }

    @Override
    public Message selectallByTeachingDirectorJurisdictionSix(int staffId) {
        List<InstructionalSupervision> list = instructionalSupervisionMapper.selectByInstructionalSupervisionTeachingSupervisorId(staffId);
        for (InstructionalSupervision instructionalSupervision:list)
            initInstructionalSupervision(instructionalSupervision);
        return Message.success(null).add(list);
    }

    @Override
    public Message selectallByprincipalTeacherJurisdictionSeven(int staffId) {
        List<InstructionalSupervision> list = instructionalSupervisionMapper.selectAllByInstructionalSupervisionPrincipalTeacherId(staffId);
        for (InstructionalSupervision instructionalSupervision:list)
            initInstructionalSupervision(instructionalSupervision);
        return Message.success(null).add(list);
    }

    private InstructionalSupervision initInstructionalSupervision(InstructionalSupervision record){
        //设置发起人名称
        if (record.getInstructionalSupervisionPostUserId() != null) {
            record.setInstructionalSupervisionPostUserName(staffMapper.selectByPrimaryKey(record.getInstructionalSupervisionPostUserId()).getStaffName());
        }
        //设置授课老师名称
        if (record.getInstructionalSupervisionTeacherId()!=null)
            record.setInstructionalSupervisionTeacherName(staffMapper.selectByPrimaryKey(record.getInstructionalSupervisionTeacherId()).getStaffName());
        //设置教学主管名称
        if (record.getInstructionalSupervisionTeachingSupervisorId()!=null)
            record.setInstructionalSupervisionTeachingSupervisorName(staffMapper.selectByPrimaryKey(record.getInstructionalSupervisionTeachingSupervisorId()).getStaffName());
        //设置主责老师名称
        if (record.getInstructionalSupervisionPrincipalTeacherId()!=null)
            record.setInstructionalSupervisionPrincipalTeacherName(staffMapper.selectByPrimaryKey(record.getInstructionalSupervisionPrincipalTeacherId()).getStaffName());

        return record;
    }
}
